package editor;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

import networking.SMap;


@SuppressWarnings("serial")
public class MapPanel extends JPanel
{
	int[][] array;
	int[][] highlight;
	int width;
	int height;
	private boolean hL;
	
	public MapPanel(int sizeX, int sizeY)
	{
		width = sizeX;
		height = sizeY;
		
		array = new int[width][height];
		for(int i=0; i<width; i++)
		{
			for(int j=0; j<height; j++)
			{
				array[i][j] = Color.black.getRGB();
			}
		}
		
	}
	public void paintComponent(Graphics g)
	{
		
		for(int i=0; i<width; i++)
		{
			for(int j=0; j<height; j++)
			{
				g.setColor(new Color(array[i][j]));
				g.fillRect(j*10, i*10, 10, 10);
				g.setColor(Color.white);
				g.drawRect(j*10, i*10, 9, 9);
			}
		}
		if(hL)
		{
			for(int i=0; i<width; i++)
			{
				for(int j=0; j<height; j++)
				{
					g.setColor(new Color(highlight[i][j]));
					g.fillRect(j*10, i*10, 10, 10);
					g.setColor(Color.white);
					g.drawRect(j*10, i*10, 9, 9);
				}
			}
			hL = false;
		}
	}
	public SMap testMap()
	{
		SMap map = new SMap(array, "");
		return map;
	}
	public void click(int x, int y, int selectedColor) 
	{
		
		array[y/10][x/10] = selectedColor;
		repaint();
	}
	public void clearHighLight() 
	{
		highlight = new int[array.length][array[0].length];
		for(int i = 0; i < array.length; i++)
		{
			for(int j = 0; j < array[0].length; j++)
			{
				highlight[i][j] = array[i][j];
			}
		}
		hL = false;
		
	}
	public void highlight(int x, int y, int selectedColor) 
	{
		hL = true;
		highlight[y/10][x/10] = selectedColor;
		repaint();
		
	}
	public void setMap(SMap cMAP) 
	{
		array = cMAP.getMap();
	}
	public int getValue(int i, int j) 
	{
		return array[i][j];
	}
	public int[][] getMap() {
		
		return array;
	}
	
}